package com.cnap.multiclouldmgmt.service;

import com.cnap.multiclouldmgmt.model.RepByPage;
import com.cnap.multiclouldmgmt.model.k8sModels.*;
import com.cnap.multiclouldmgmt.model.k8sMonitorModels.SvcMonitorModel;
import com.cnap.multiclouldmgmt.model.knowledge.ErrorInjectModel;
import io.fabric8.kubernetes.api.model.OwnerReference;
import io.fabric8.kubernetes.api.model.apps.DaemonSet;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.api.model.apps.ReplicaSet;
import io.fabric8.kubernetes.api.model.apps.StatefulSet;
import io.fabric8.kubernetes.api.model.metrics.v1beta1.PodMetrics;
import io.fabric8.kubernetes.client.KubernetesClient;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author dyq
 * 基础服务
 */
public interface K8sClusterService {

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     * @throws Exception
     */
    int getK8sClusterMasterNodeNum(String cloudVendor, String k8sClusterName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param nodeName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<NodeModel> getK8sClusterNodeInfosByConditions(String cloudVendor, String k8sClusterName, String nodeName, String keyword,
                                                            int pageSize, int pageNo) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param nodeName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @param labelKey
     * @param labelValue
     * @return
     * @throws Exception
     */
    RepByPage<NodeModel> getK8sClusterNodeInfosByConditions(String cloudVendor, String k8sClusterName, String nodeName,String keyword,
                                                            int pageSize, int pageNo,String labelKey,String labelValue) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<NodeModel> getK8sClusterNodeInfosByConditions(String cloudVendor, String k8sClusterName, String keyword,
                                                 int pageSize, int pageNo) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<NodeModel> getK8sClusterNodeInfosByConditions(String cloudVendor, String k8sClusterName, String keyword,
                                                            int pageSize, int pageNo,String accountName) throws Exception;
    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     * @throws Exception
     */
    int getK8sClusterNodeNum(String cloudVendor, String k8sClusterName) throws Exception;


    /**
     *
     * @param k8sClusterBasicModel
     * @return
     * @throws Exception
     */
    int getK8sClusterNodeNum(K8sClusterBasicModel k8sClusterBasicModel) throws Exception;
    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     * @throws Exception
     */
    int getK8sClusterSvcNum(String cloudVendor, String k8sClusterName) throws Exception;

    /**
     *
     * @param k8sClusterBasicModel
     * @return
     * @throws ParseException
     */
    List<NodeModel> getAllNodeInfo(K8sClusterBasicModel k8sClusterBasicModel) throws Exception;

    /**
     *
     * @param k8sClusterBasicModel
     * @param nodeName
     * @param labelKey
     * @param labelValue
     * @return
     * @throws ParseException
     */
    List<NodeModel> getAllNodeInfo(K8sClusterBasicModel k8sClusterBasicModel,String nodeName,String labelKey,String labelValue) throws Exception;

    /**
     *
     * @param k8sClusterBasicModel
     * @param nameSpace
     * @return
     * @throws ParseException
     */
    List<PodModel> getAllPodsInfo(K8sClusterBasicModel k8sClusterBasicModel, String nameSpace) throws Exception;

    /**
     *
     * @param k8sClusterBasicModel
     * @param nameSpace
     * @param podName
     * @return
     * @throws ParseException
     */
    List<PodModel> getAllPodsInfo(K8sClusterBasicModel k8sClusterBasicModel,String nameSpace,String podName) throws Exception;

    /**
     *
     * @param nameSpace
     * @param k8sClient
     * @param ownerReferences
     * @return
     */
    WorkLoadModel getOwnerReference(String nameSpace,KubernetesClient k8sClient,List<OwnerReference> ownerReferences);

    /**
     *
     * @param nameSpace
     * @param k8sClient
     * @param replicaSetName
     * @return
     */
    ReplicaSet getReplicaSetByName(String nameSpace, KubernetesClient k8sClient, String replicaSetName);

    /**
     *
     * @param nameSpace
     * @param k8sClient
     * @param deploymentName
     * @return
     */
    Deployment getDeploymentByName(String nameSpace, KubernetesClient k8sClient, String deploymentName);

    /**
     *
     * @param nameSpace
     * @param k8sClient
     * @param statefulSetName
     * @return
     */
    StatefulSet getStatefulSetByName(String nameSpace, KubernetesClient k8sClient, String statefulSetName);

    /**
     *
     * @param nameSpace
     * @param k8sClient
     * @return
     */
    List<PodMetrics> getPodMetricsByNs(String nameSpace,KubernetesClient k8sClient);

    /**
     *
     * @param k8sClusterBasicModel
     * @return
     */
    List<String> getAllNameSpaceNames(K8sClusterBasicModel k8sClusterBasicModel);

    /**
     *
     * @param nodeModel
     * @throws Exception
     */
    void editK8sClusterNodeInfo(NodeModel nodeModel) throws Exception;

    /**
     *
     * @param k8sClusterIp
     * @param nodeName
     * @throws Exception
     */
    void delK8sClusterNode(String k8sClusterIp,String nodeName) throws Exception;


    /**
     *
     * @param k8sClusterBasicModel
     * @param nodeName
     * @throws Exception
     */
    void delK8sClusterNode(K8sClusterBasicModel k8sClusterBasicModel,String nodeName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<NameSpaceModel> getK8sClusterNameSpaces(String cloudVendor, String k8sClusterName, String keyword,
                                                      int pageSize, int pageNo,String accountName) throws Exception;
    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<NameSpaceModel> getK8sClusterNameSpaces(String cloudVendor, String k8sClusterName, String keyword,
                                                      int pageSize, int pageNo) throws Exception;

    /**
     *
     * @param k8sClusterBasicModel
     * @return
     * @throws ParseException
     */
    List<NameSpaceModel> getAllNameSpaceInfo(K8sClusterBasicModel k8sClusterBasicModel) throws ParseException;

    /**
     *
     * @param k8sClusterBasicModel
     * @param nameSpace
     * @return
     * @throws ParseException
     */
    List<SvcModel> getAllSvcInfo(K8sClusterBasicModel k8sClusterBasicModel,String nameSpace) throws ParseException;

    /**
     *
     * @param k8sClusterBasicModel
     * @param nameSpace
     * @param svcName
     * @return
     * @throws ParseException
     */
    SvcModel getSvcInfo(K8sClusterBasicModel k8sClusterBasicModel,String nameSpace,String svcName) throws ParseException;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @return
     * @throws Exception
     */
    int getAllSvcNum(String cloudVendor, String k8sClusterName) throws Exception;

    /**
     *
     * @param nameSpaceModel
     * @throws Exception
     */
    void addK8sClusterNameSpaces(NameSpaceModel nameSpaceModel) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param nameSpaceName
     * @throws Exception
     */
    void delK8sClusterNameSpaces(String cloudVendor, String k8sClusterName, String nameSpaceName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param svcName
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<WorkLoadModel> getK8sClusterWorkLoads(String cloudVendor, String k8sClusterName, String keyword,
                                                    String svcName,int pageSize, int pageNo,String accountName) throws Exception;
    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param svcName
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<WorkLoadModel> getK8sClusterWorkLoads(String cloudVendor, String k8sClusterName, String keyword,
                                                     String svcName,int pageSize, int pageNo) throws Exception;

    /**
     *
     * @param k8sClusterBasicModel
     * @param nameSpace
     * @return
     * @throws ParseException
     */
    List<WorkLoadModel> getAllWorkLoads(K8sClusterBasicModel k8sClusterBasicModel,String nameSpace) throws ParseException;

    /**
     *
     * @param nameSpace
     * @param k8sClient
     * @param daemonSetName
     * @return
     */
    DaemonSet getDaemonSetByName(String nameSpace, KubernetesClient k8sClient, String daemonSetName);

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param yaml
     * @throws Exception
     */
    void addK8sClusterWorkLoad(String cloudVendor, String k8sClusterName,String yaml) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param workdLoadName
     * @param namespace
     * @param workLoadKind
     * @param replicas
     * @throws Exception
     */
    void editK8sClusterWorkLoadReplicas(String cloudVendor, String k8sClusterName,String workdLoadName,String namespace,
                                            String workLoadKind,int replicas) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param workLoadName
     * @param namespace
     * @param workLoadKind
     * @param containerModels
     * @throws Exception
     */
    void editK8sClusterWorkLoadContainers(String cloudVendor, String k8sClusterName,String workLoadName,String namespace,
                                          String workLoadKind,List<ContainerModel> containerModels) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param workLoadName
     * @param workLoadKind
     * @throws Exception
     */
    void delK8sClusterWorkLoad(String cloudVendor,String k8sClusterName,
                          String namespace,String workLoadName,String workLoadKind) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param namespace
     * @param svcName
     * @param workLoadName
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<PodModel> getK8sClusterPods(String cloudVendor, String k8sClusterName, String keyword,
                                           String namespace,String svcName,String workLoadName,
                                           int pageSize, int pageNo) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param namespace
     * @param svcName
     * @param workLoadName
     * @param nodeName
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<PodModel> getK8sClusterPods(String cloudVendor, String k8sClusterName, String keyword,
                                          String namespace,String svcName,String workLoadName,String nodeName,
                                          int pageSize, int pageNo) throws Exception;


    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param namespace
     * @param svcName
     * @param workLoadName
     * @param nodeName
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<PodModel> getK8sClusterPods(String cloudVendor, String k8sClusterName, String keyword,
                                          String namespace,String svcName,String workLoadName,String nodeName,
                                          int pageSize, int pageNo,String accountName) throws Exception;
    /**
     *
     * @param k8sClusterBasicModel
     * @param nameSpace
     * @param svcName
     * @return
     */
    SvcModel getSvcModelByName(K8sClusterBasicModel k8sClusterBasicModel,String nameSpace,String svcName);

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param podName
     * @throws Exception
     */
    void delK8sClusterPod(String cloudVendor, String k8sClusterName, String namespace,String podName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param podName
     * @return
     * @throws Exception
     */
    List<ContainerModel> getK8sClusterPodContainers(String cloudVendor, String k8sClusterName,
                                                     String namespace,String podName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<SvcModel> getK8sClusterSvcs(String cloudVendor, String k8sClusterName, String keyword,
                      int pageSize, int pageNo) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param keyword
     * @param pageSize
     * @param pageNo
     * @return
     * @throws Exception
     */
    RepByPage<SvcModel> getK8sClusterSvcs(String cloudVendor, String k8sClusterName, String keyword,
                                          int pageSize, int pageNo,String accountName) throws Exception;


    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param yaml
     * @throws Exception
     */
    void addK8sClusterSvc(String cloudVendor, String k8sClusterName,String yaml) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param svcType
     * @param svcName
     * @param port
     * @param targetPort
     * @param nodePort
     * @param selectorModels
     * @throws Exception
     */
    void editK8sClusterSvc(String cloudVendor, String k8sClusterName,String namespace,String svcType,String svcName,int port,int targetPort,int nodePort,
                           List<KeyValueModel> selectorModels) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param svcName
     * @throws Exception
     */
    void delK8sClusterSvc(String cloudVendor, String k8sClusterName, String namespace,
                     String svcName) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param namespace
     * @param svcName
     * @param yaml
     * @throws Exception
     */
    void editK8sClusterSvcByYaml(String cloudVendor, String k8sClusterName,String namespace,String svcName,String yaml) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param svcMonitorModels
     * @return
     * @throws Exception
     */
    List<SvcMonitorModel> getSvcMonitorInfo(String cloudVendor, String k8sClusterName, List<SvcMonitorModel> svcMonitorModels) throws Exception;

    /**
     *
     * @param cloudVendor
     * @param k8sClusterName
     * @param yaml
     * @throws Exception
     */
    void editK8sClusterWorkLoadByYaml(String cloudVendor, String k8sClusterName, String yaml) throws Exception;

    /**
     *
     * @param k8sClusterName
     * @param userName
     * @param beginTime
     * @param reason
     * @param pageSize
     * @param pageNo
     * @return
     */
    RepByPage<EventModel> getK8sClusterEvents(String k8sClusterName, String userName, String beginTime, String reason, int pageSize, int pageNo);

    /**
     *
     * @param k8sClusterName
     * @param userName
     * @param beginTime
     * @param reason
     * @param pageSize
     * @param pageNo
     * @return
     */
    RepByPage<EventModel> getK8sClusterEvents(String k8sClusterName, String userName, String beginTime, String reason,
                                              int pageSize, int pageNo,String endTime,String cloudVendor);

    /**
     *
     * @param k8sClusterName
     * @param userName
     * @param beginTime
     * @param reason
     * @param pageSize
     * @param pageNo
     * @return
     */
    RepByPage<EventModel> getK8sClusterEvents(String k8sClusterName, String userName, String beginTime, String reason,
                                              int pageSize, int pageNo,String endTime);

    /**
     *
     * @param k8sClusterName
     * @param namespace
     * @param svcName
     * @return
     * @throws ParseException
     */
    SvcMonitorModel getSvcPodSpark(String k8sClusterName, String namespace, String svcName) throws ParseException;

    /**
     *
     * @param k8sClusterName
     * @param namespace
     * @param svcName
     * @return
     * @throws ParseException
     */
    SvcMonitorModel getSvcPodFlinks(String k8sClusterName, String namespace, String svcName) throws ParseException;

    /**
     *
     * @param k8sClient
     * @return
     */
    String getK8sClusterInnerIp(KubernetesClient k8sClient);

    /**
     *
     * @param k8sClusterBasicModel
     * @param nodeName
     * @param labelKey
     * @param labelValue
     * @throws Exception
     */
    void addNodeLabel(K8sClusterBasicModel k8sClusterBasicModel,String nodeName,String labelKey,String labelValue) throws Exception;

    /**
     *
     * @param k8sClusterName
     * @param nodeName
     * @param labelKey
     * @param labelValue
     * @throws Exception
     */
    void addNodeLabel(String k8sClusterName,String nodeName,String labelKey,String labelValue) throws Exception;


    /**
     *
     * @param k8sClusterName
     * @param nodeName
     * @param labelKey
     * @param labelValue
     * @throws Exception
     */
    void changeNodeLabel(String k8sClusterName,String nodeName,String labelKey,String labelValue) throws Exception;

    /**
     *
     * @param k8sClusterName
     * @param nodeName
     * @param labelKey
     * @throws Exception
     */
    void delNodeLabel(String k8sClusterName,String nodeName,String labelKey) throws Exception;
    /**
     *
     * @param nodeModel
     */
    void addK8sClusterNode(NodeModel nodeModel);


    /**
     *
     * @param k8sClusterIp
     */
    K8sClusterBasicModel installCnapScheduleAgent(String k8sClusterIp,String arch) throws Exception;

    /**
     *
     * @param K8sClusterIp
     * @return
     */
    PodModel getUtListPods(String K8sClusterIp) throws Exception;

    /**
     *
     * @param k8sClusterIp
     * @return
     */
    boolean checkSvcExist(String k8sClusterIp) throws Exception;

    void refeshK8sClusterInfos(String k8sClusterIp) throws Exception;

    void stopErrorInject(ErrorInjectModel errorInjectModel) throws Exception;

    String runErrorInject(ErrorInjectModel errorInjectModel) throws Exception;

    void microSvcPress(ErrorInjectModel errorInjectModel) throws ParseException;

    boolean checkSvcSuspend(K8sClusterBasicModel k8sClusterBasicModel, String svcId);
}
